/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dotexe.webframework.core.communication;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
 *
 * @author jovan.tomasevic
 * complete
 */
public class CallBackResult extends JSONObject {

    // ControlID
    public String getControlID() throws JSONException{
        return this.getString("ControlID");
    }
    public void setControlID(String value) throws JSONException{
        if(value == null){
            this.put("ControlID", JSONObject.NULL);
        }
        else{
            this.put("ControlID", value);
        }
    }
    // ElementID
    public String getElementID() throws JSONException{
        return this.getString("ElementID");
    }
    public void setElementID(String value) throws JSONException{
        if(value == null){
            this.put("ElementID", JSONObject.NULL);
        }
        else{
            this.put("ElementID", value);
        }
    }
    // InfoMessage
    public JSONArray getInfoMessage() throws JSONException{
        return (JSONArray)this.get("InfoMessage");
    }
    public void setInfoMessage(JSONArray value) throws JSONException{
       if(value == null){
            this.put("InfoMessage", JSONObject.NULL);
        }
        else{
            this.put("InfoMessage", value);
        }
    }

    // Error
    public ErrorMessage getError() throws JSONException{
        if(this.getError()!=JSONObject.NULL){
            return (ErrorMessage) this.get("Error");
        }
        else{
            return null;
        }
    }
    public void setError(ErrorMessage value) throws JSONException{
       if(value == null){
            this.put("Error", JSONObject.NULL);
        }
        else{
            this.put("Error", value);
        }
    }

    // ClientActions
    public JSONArray getClientActions() throws JSONException{
        return (JSONArray)this.get("ClientActions");
    }
    public void setClientActions(JSONArray value) throws JSONException{
        if(value == null){
            this.put("ClientActions", JSONObject.NULL);
        }
        else{
            this.put("ClientActions", value);
        }
    }

    public CallBackResult() throws JSONException{
        this.put("ControlID", JSONObject.NULL);
        this.put("ElementID",JSONObject.NULL);
        this.put("InfoMessage",new JSONArray());
        this.put("Error", JSONObject.NULL);
        this.put("ClientActions",new JSONArray());
    }
    public void clear() throws JSONException
    {
        this.put("InfoMessage", new JSONArray());
        this.put("ClientActions",  new JSONArray());
        this.put("ControlID", "");
        this.put("ElementID", "");
        this.put("Error", "");
    }
    public Boolean isEmpty() throws JSONException
    {
        return /*getBindingSources().length() == 0 &&*/
            getInfoMessage().length() == 0 &&
            this.getClientActions().length() == 0; //&&
            //getError() == null;
    }
    /**
    public CallBackResult Copy() throws JSONException
    {
        CallBackResult callbackResult = new CallBackResult();
        callbackResult.setElementID(this.getElementID());
        callbackResult.setControlID (this.getControlID());
        //JSONArray BindingSources = this.getBindingSources();
        JSONArray ClientActions = this.getClientActions();
        JSONArray InfoMessage = this.getInfoMessage();

//        if(BindingSources != null){
//            for(int i = 0; i<BindingSources.length();i++){
//                JSONArray obj = BindingSources.getJSONArray(i);
//                callbackResult.getBindingSources().put(obj);
//            }
//        }

        if(ClientActions != null){
            for(int i = 0; i<ClientActions.length();i++){
                Object obj = ClientActions.get(i);
                callbackResult.getClientActions().put(obj);
            }
        }

        if(InfoMessage != null){
            for(int i = 0; i<InfoMessage.length();i++){
                Object obj = InfoMessage.get(i);
                callbackResult.getInfoMessage().put(obj);
            }
        }
        // TODO: !!! jovan.tomasevic.
        callbackResult.setError(null);
        return callbackResult;
    }
     */

}
